import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// 获取环境变量
const API_URL = process.env.VITE_API_URL || 'http://localhost:3000'
const MODE = process.env.NODE_ENV || 'development'

export default defineConfig({
  plugins: [vue()],
  server: {
    port: parseInt(process.env.VITE_PORT) || 5173,
    proxy: {
      '/socket.io': {
        target: API_URL,
        ws: true,
        changeOrigin: true
      }
    }
  },
  build: {
    outDir: 'dist',
    assetsDir: 'assets',
    sourcemap: MODE === 'development',
    minify: MODE === 'production' ? 'esbuild' : false,
    rollupOptions: {
      output: {
        manualChunks: {
          'vue-vendor': ['vue', 'vue-router'],
          'socket-vendor': ['socket.io-client']
        }
      }
    },
    chunkSizeWarningLimit: 1000
  },
  define: {
    __API_URL__: JSON.stringify(API_URL),
    __MODE__: JSON.stringify(MODE)
  }
})

